package cn.tedu._01mvcboot01.controller;

import cn.tedu._01mvcboot01.pojo.BmiDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BMIController {
    @GetMapping("/bmi")
    @ResponseBody
    public String bmi(BmiDto bmiDto) {
        Double height=bmiDto.getHeight();
        Double weight=bmiDto.getWeight();
        double bmi = weight / (height * height);
        if (bmi < 18.5) {
            return "过轻";
        } else if (bmi < 24) {
            return "正常";
        }
            return " 肥胖";
        }


    /**
     * 路径变量中传递数据
     * 1.请求地址：/bmi/{height}/{weight}
     * 2.请求方法：GET
     * 3.请求参数：height weight
     * 4.返回响应：偏瘦。。。。。
     */

    @GetMapping("/bmi/{height}/{weight}")
    @ResponseBody
    public String bmi2(@PathVariable("height") Double height,
                       @PathVariable("weight") Double weight) {
        double bmi = weight / (height * height);
        if (bmi < 18.5) {
            return "偏瘦";
        } else if (bmi < 24) {
            return "正常";
        }else if (bmi < 28){
            return "偏胖";
        }
        return "偏胖";
    }
}

